package com.abvnet.project.water.sewage.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.system.dict.domain.DictData;
import com.abvnet.project.system.dict.service.IDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 污水类型信息操作处理
 * 
 * @author duj
 * @date 2019-07-02
 */
@Controller
@RequestMapping("/sewage/sewageType")
public class SewageTypeController extends BaseController {
    private String prefix = "sewage/sewageType";

    @Autowired
    private IDictDataService dictDataService;
	
	@RequiresPermissions("sewage:sewageType:list")
	@GetMapping()
	public String sewageType()
	{
	    return prefix + "/sewageType";
	}
	
	/**
	 * 查询污水类型列表
	 */
	@RequiresPermissions("sewage:sewageType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list() {
        DictData dictData = new DictData();
        dictData.setDictType("sewage_type");
        startPage();
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        return getDataTable(list);
	}
	
	/**
	 * 新增污水类型
	 */
    @GetMapping("/add/{dictType}")
    public String add(@PathVariable("dictType") String dictType, ModelMap mmap) {
        mmap.put("dictType", dictType);
        return prefix + "/add";
    }
	
	/**
	 * 新增保存污水类型
	 */
	@RequiresPermissions("sewage:sewageType:add")
	@Log(title = "污水类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(DictData dict) {
        return toAjax(dictDataService.insertDictData(dict));
	}

	/**
	 * 修改污水类型
	 */
    @GetMapping("/edit/{dictCode}")
    public String edit(@PathVariable("dictCode") Long dictCode, ModelMap mmap) {
        mmap.put("dict", dictDataService.selectDictDataById(dictCode));
        return prefix + "/edit";
    }
	
	/**
	 * 修改保存污水类型
	 */
	@RequiresPermissions("sewage:sewageType:edit")
	@Log(title = "污水类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
    public AjaxResult editSave(DictData dict) {
        return toAjax(dictDataService.updateDictData(dict));
    }
	
	/**
	 * 删除污水类型
	 */
	@RequiresPermissions("sewage:sewageType:remove")
	@Log(title = "污水类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
        return toAjax(dictDataService.deleteDictDataByIds(ids));
	}
	
}
